package com.hkyp.ss.course.apis.utils;


import java.util.Calendar;

public class MillisecondUtil {



    /**
     * MonthToken
     *获得当月15号0点毫秒值
     * 测试成功
     */
    public static Long getMidMonthZero() {

        Calendar calendar = Calendar.getInstance();
        int now_y = calendar.get(Calendar.YEAR);//得到年份
        int now_m = calendar.get(Calendar.MONTH);//得到月份
        calendar.clear();
        calendar.set(now_y,now_m,15);

        return calendar.getTimeInMillis();
    }

    /**
     * 获得今天0点毫秒值
     * 测试成功
     */
    public static Long getTodayZero() {

        Calendar calendar = Calendar.getInstance();
        int now_y = calendar.get(Calendar.YEAR);//得到年份
        int now_m = calendar.get(Calendar.MONTH);//得到月份
        int now_d = calendar.get(Calendar.DATE);//得到月份中今天的号数
        calendar.clear();
        calendar.set(now_y, now_m, now_d);

        return calendar.getTimeInMillis();
    }

    /**
     * 获得昨天0点毫秒值
     * 测试成功
     */
    public static Long getYesterdayZero() {

        Calendar calendar = Calendar.getInstance();
        int now_y = calendar.get(Calendar.YEAR);//得到年份
        int now_m = calendar.get(Calendar.MONTH);//得到月份
        int now_d = calendar.get(Calendar.DATE) - 1;//得到月份中今天的号数
        calendar.clear();
        calendar.set(now_y, now_m, now_d);

        return calendar.getTimeInMillis();
    }

    /**
     * 获得明天零点毫秒值
     * 测试成功
     */
    public static Long getTomorrowZero() {

        Calendar calendar = Calendar.getInstance();
        int now_y = calendar.get(Calendar.YEAR);//得到年份
        int now_m = calendar.get(Calendar.MONTH);//得到月份
        int now_d = calendar.get(Calendar.DATE) + 1;//得到月份中今天的号数
        calendar.clear();
        calendar.set(now_y, now_m, now_d);

        return calendar.getTimeInMillis();
    }

    /**
     * 获得当月一日0点毫秒值
     * 测试成功
     */
    public static Long getCurrentMonthZero() {

        //方法2：推荐使用
        Calendar calendar = Calendar.getInstance();
        int now_y = calendar.get(Calendar.YEAR);//得到年份
        int now_m = calendar.get(Calendar.MONTH);//得到月份
        int now_d = calendar.get(Calendar.DATE);//得到月份中今天的号数

        calendar.clear();

        calendar.set(now_y, now_m, 1);

        return calendar.getTimeInMillis();
    }

    /**
     * 获得下一个月一日0点毫秒值
     * 测试成功
     */
    public static Long getNextMonthZero() {

        Calendar calendar = Calendar.getInstance();
        int now_y = calendar.get(Calendar.YEAR);//得到年份
        int now_m = calendar.get(Calendar.MONTH)+1;//得到月份

        calendar.clear();

        calendar.set(now_y, now_m, 1);

        return calendar.getTimeInMillis();
    }

    /**
     * 获得今天几号
     * 测试成功
     */
    public static int getToday() {

        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.DATE);//得到月份中今天的号数
    }

}
